package com.nus.servlets;

import com.nus.beans.Project;
import com.nus.beans.User;
import com.nus.database.ProjectsDBManager;
import com.nus.database.UserDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 9/26/12
 * Time: 12:44 AM
 * To change this template use File | Settings | File Templates.
 */
public class ViewProjectsServlet extends AbstractServlet{
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        doGet(request, response);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        Connection connection = getUserDatabaseConnection(request);
        ProjectsDBManager projectManager = new ProjectsDBManager(connection);
        List<Project> projectsList = projectManager.loadProjects();

        projectManager.close();

        request.setAttribute("projectsList", projectsList);
        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/view_projects.jsp");
        dispatcher.forward(request, response);

    }
}
